package com.lwj.mallchat.common.user.service.handler;

import com.lwj.mallchat.common.user.service.WxMsgService;
import com.lwj.mallchat.common.user.service.adapter.TextBuilder;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.Map;

@Component
public class ScanHandler extends AbstractHandler {

    @Autowired
    private WxMsgService wxMsgService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map,
                                    WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {

        // 扫码事件处理
        return wxMsgService.scan(wxMpService, wxMpXmlMessage);
//        String code = wxMpXmlMessage.getEventKey();
////        String open_id = wxMpXmlMessage.getFromUser();
////        System.out.println(wxMpService.getWxMpConfigStorage().getAppId());
////        String authUrl = String.format(URL, wxMpService.getWxMpConfigStorage().getAppId(), URLEncoder.encode(callback + "/wx/portal/public/callBack"));
////        String content = "请点击登录: <a href=\"" + authUrl + "\">登录</a>";
////        WxMpXmlOutMessage ans = TextBuilder.build(content, wxMpXmlMessage);
////        return ans;
    }

}
